﻿
function fChkNick(sUserID) {
  var str=sUserID;

  for(i=0;i<str.length;i++){
    ch=input_check(str.substr(i,1))

    if(ch=='4'){
      document.location="/member/myinfo.php";
      window.window.alert("닉네임에 특수문자가 포함되어 있습니다. 회원정보에서 수정하세요");

      return;
    }
  }
}
// 폼전송전 공백제거(write)
function all_textForm_trim(frm) {
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].type == "text") {
      frm.elements[i].value = trim(frm.elements[i].value);
    }
  }
}
function checkAll() {
  var f = document.getElementById("sublist").getElementsByTagName("INPUT");

  for (x = 0; x < f.length; x++) {
    f[x].checked = arguments[0].checked;
  }
}

// trim 함수
function trim(str){
  // 정규 표현식을 사용하여 화이트스페이스를 빈문자로 전환
  str = str.replace(/^\s*/,'').replace(/\s*$/, '');
  return str;
}

// 원도우 창 오픈 (해상도에 따라 가운데로 열기)
function winOpenCenter (doc, wname, width, height) {
  var screenWidth  = screen.availWidth;
  var screenHeight = screen.availHeight;

  var intLeft = (screenWidth - width) / 2;
  var intTop  = (screenHeight - height) / 2

  window.open(doc, wname, 'scrollbars=no,resizable=no,top='+intTop+',left='+intLeft+',width='+width+',height='+height);
}

function winOpenCenter2 (doc, wname, width, height) {
  var screenWidth  = screen.availWidth;
  var screenHeight = screen.availHeight;

  var intLeft = (screenWidth - width) / 2;
  var intTop  = (screenHeight - height) / 2

  window.open(doc, wname, 'scrollbars=yes,resizable=no,top='+intTop+',left='+intLeft+',width='+width+',height='+height);
}

function wopen(url, t, w, h) {
  var sw;
  var sh;
  sw = (screen.Width - w) / 2;
  sh = (screen.Height - h) / 2;
  window.open(url, t, 'Width='+w+'px, Height='+h+'px, Left='+sw+', Top='+sh);
}

function cal_byte(aquery, f1, f2, maxStr, msg) {
  var tmpStr;
  var temp=0;
  var onechar;
  var tcount;
  tcount = 0;

  if (aquery == '') aquery = $("textarea[name='"+f1+"']").val();

  tmpStr = new String(aquery);
  temp = tmpStr.length;

  for (k=0; k < temp; k++) {
    onechar = tmpStr.charAt(k);
    if (escape(onechar).length > 4) tcount += 2;
    else if (onechar != '\r')       tcount++;
  }

  $("#"+f2).html(tcount);
  if (tcount > maxStr) {
    reserve = tcount - maxStr;
    window.alert(msg);
    nets_check(f1, f2, maxStr);
    return false;
  }
}

// 자료에 공백이 있는지 체크
function IsEmpty(data) {
  for (var i=0; i < data.length; i++) {
    if (data.substring(i,i+1) != " ") return false;
  }
  return true;
}

function input_check(check_string) {
  var char_ASCII = check_string.charCodeAt(check_string.length-1);
  if ((char_ASCII>=33 && char_ASCII<=47) || (char_ASCII>=58 && char_ASCII<=64) || (char_ASCII>=91 && char_ASCII<=96) || (char_ASCII>=123 && char_ASCII<=126))	return '4';
}
function nets_check(f1, f2, maxStr) {
  var tmpStr;
  var temp = 0;
  var onechar;
  var tcount;
  tcount = 0;

  tmpStr = new String($("textarea[name='"+f1+"']").val());
  temp = tmpStr.length;

  for (k=0;k<temp;k++) {
    onechar = tmpStr.charAt(k);

    if (escape(onechar).length > 4)  tcount += 2;
    else if (onechar != '\r')        tcount++;

    if (tcount > maxStr) {
      tmpStr = tmpStr.substring(0, k);
      break;
    }
  }

  $("textarea[name='"+f1+"']").val(tmpStr);
  cal_byte(tmpStr, f1, f2, maxStr);

  return tmpStr;
}

function purge(d) {
  var a = d.attributes, i, l, n;
  if (a) {
    l = a.length;
    for (i = 0; i < l; i += 1) {
      n = a[i].name;
      if (typeof d[n] === 'function') {
        d[n] = null;
      }
    }
  }
  a = d.childNodes;
  if (a) {
    l = a.length;
    for (i = 0; i < l; i += 1) {
      purge(d.childNodes[i]);
    }
  }
}

function submenu_show(cid, myid) {
  var str = "<ol style=\"list-style:none;margin:0;padding-top:5px\">";
  str += "<li style=\"width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;\"><a href=\"/board/bulletin/mycommunity.php?cid="+cid+"\" target=\"_blank\">회원정보</a></li>";
  str += "<li style=\"width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;\"><a href=\"javascript:memo2user('" + cid + "');\" class=\"uicon\"> 쪽지보내기</a></li>";
  str += "<li style=\"width:130px;text-align:left;padding-left:10px;color:4c4c4c;\"><a href=\"/board/bulletin/mycommunity.php?cid="+cid+"\" target=\"_blank\"class=\"uicon\">작성글 보기</a></li>";
  str += "</ol>";

  $("#submenusel").html(str);
  $("#submenusel").show('fast');


  $("#submenusel").css({
    'left' : left_pos,
    'top' : top_pos,
    'z-index' : 1001
  });
}

function submenu_level(cid) {
  $.ajax({
    url: "/board_renew/bulletin/proc/get_member_data.php",
    type:"post",
    dataType: "xml",
    data:{
      "cid":cid
    },
    beforeSend:function(xhr) {
      $("#submenusel").empty()
      $("#submenusel").hide();
    },
    success:function(data, textStatus) {
      var conts = $(data).find("cont");
      if (!conts) return;
      if (conts.length > 0) {
        var cont = conts.get(0);

        var strlevel = "<ol style=\"list-style:none;margin:0;padding-top:5px\">";
        strlevel += "<li style=\"width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;\">";
        strlevel += "<span style=\"display:inline-block;width:40px;\">레벨</span>" + $(cont).find("level").text();
        strlevel += "</li>";
        strlevel += "<li style=\"width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;\">";
        strlevel += "<span style=\"display:inline-block;width:40px;\">순위</span>" + $(cont).find("rankey").text();
        strlevel += "</li>";
        strlevel += "<li style=\"width:130px;text-align:left;padding-left:10px;color:4c4c4c;\">";
        strlevel += "<span style=\"display:inline-block;width:40px;\">포인트</span>" + $(cont).find("score").text();
        strlevel += "</li>";
        strlevel += "</ol>";

        $("#submenusel").html(strlevel);
        $("#submenusel").show();
        $("#submenusel").css({
          'left' : left_pos,
          'top' : top_pos,
          'z-index' : 1001
        });
      }
    },
    error:function(xhr, textStatus) {
      $("#submenusel").empty()
      $("#submenusel").hide();
    },
    complete:function(xhr, textStatus) {
    }
  });
}
function memo2user (cid) {
  var screenWidth  = screen.availWidth;
  var screenHeight = screen.availHeight;

  var intLeft = (screenWidth - 626) / 2;
  var intTop  = (screenHeight - 670) / 2

  window.open('/board/note/send_memo.php?cid=' + cid + '&ndc=Y', 'receive_list', 'scrollbars=no,resizable=no,top='+intTop+',left='+intLeft+',width=615,height=400');
}